.PHONY: help all clean gcc ghc scala

SHELL  := /bin/bash
TOPDIR := $(shell pwd)
PKGTOOL = pkgtool -v -v -v
PKGTOOL += --topdir=${TOPDIR}
PKGTOOL += --specdirs=${TOPDIR}/SPECS  
PKGTOOL += --tarballdirs=${TOPDIR}/SOURCES 
PKGTOOL += --sourcedirs=${TOPDIR}/SOURCES 
PKGTOOL += --download --download-to=${TOPDIR}/SOURCES 
PKGTOOL += --pkgformat=datastream

help:
	@echo "info: make all"
	@echo "- make < gcc | ghc | scala >"

# libedit
libedit-pkg: BUILD = pkgbuild --pkgformat=datastream
libedit-pkg: libedit

libedit-pkg-dir: BUILD = pkgbuild
libedit-pkg-dir: libedit

libedit: assert-BUILD type-pkgbuild
	cd SPECS && ${BUILD} -ba --define='_topdir ${TOPDIR}' libedit-3.0.spec

# gcc
gcc:
	${PKGTOOL} build-only gcc-4.5.0.spec
	@echo "info: gcc package in PKGS"

# gmp
gmp:
	${PKGTOOL} build-only gmp-5.0.1.spec
	@echo "info: gmp package in PKGS"

# mpfr
mpfr:
	${PKGTOOL} build-only mpfr-2.4.2.spec
	@echo "info: mpfr package in PKGS"

# mpc
mpc:
	${PKGTOOL} build-only mpc-0.8.1.spec
	@echo "info: mpc package in PKGS"

# ghc
ghc:
	${PKGTOOL} build-only ghc-6.12.3.spec
	@echo "info: ghc package in PKGS"

# cabal-install
cabal-install:
	${PKGTOOL} build-only cabal-install-0.8.2.spec
	@echo "info: cabal-install package in PKGS"

# scala
scala:
	${PKGTOOL} build-only scala-2.7.7.spec
	@echo "info: scala package in PKGS"

# ruby
ruby:
	${PKGTOOL} build-only ruby-1.9.1.spec
	@echo "info: ruby package in PKGS"

# git
git:
	${PKGTOOL} build-only git-1.7.1.spec
	@echo "info: git package in PKGS"

# protobuf
protobuf:
	${PKGTOOL} build-only protobuf-2.3.0.spec
	@echo "info: protobuf package in PKGS"

# ---

clean:
	for d in BUILD PKGMAPS SPKGS; do ( [ ! -d $$d ] || ( cd $$d && rm -rf * ) ); done

assert-%:; @[ -n "$($*)" ] || ( echo error: $* is undefined && exit 126 )

type-%:; @if ! type $* >/dev/null 2>&1; then echo error: $* not found && exit 127; fi
